
export default {
  /**
   * 前端分页
   * @param srcList        源数据
   * @param current        当前页
   * @param pageSize       每页条数
   * @returns pageList    当前页数据
   * @returns total        总条数
   * @returns pageNum      总页数
   */
  sliceList(srcList, current, pageSize) {
    current = current || 1
    pageSize = pageSize || 10
    const formIndex = (current - 1) * pageSize;
    const toIndex = current * pageSize;
    const rows = srcList.slice(formIndex, Math.min(toIndex, srcList.length));
    const total = srcList.length;
    return {rows, total}
  },
  /**
   * 过滤列表
   * @param srcList       源数据
   * @param filterMap      过滤条件
   *  <pre>
   *    如果是post请求的直接传入对象，然后内部会转换成map
   *    如果是get请求，就使用MockParamsUtil.getUrlParamsExcludePageField()获取
   *  </pre>
   * @param ignoreField
   * @returns {Array}   过滤后的数据
   */
  filterList(srcList, filterMap, ...ignoreField) {
    if (ignoreField.length > 0) {
      ignoreField.forEach(item => {
        filterMap.delete(item)
      })
    }
    if (filterMap.size === 0) {
      return srcList
    }
    filterMap.forEach((value, key) => {

      srcList = srcList.filter(item => {
        if (typeof item[key] =='string') {
          return item[key].indexOf(value) !== -1
        }
        return item[key] == value
      })
    })
    return srcList
  }
}
